<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <!-- <a-input v-model="model.type" placeholder="请输入类型"  ></a-input> -->
              <!-- 文档分类改为下拉框 从字典中获取 传给后台的是中文汉字 -->
              <j-dict-select-tag v-model="model.type" placeholder="请选择类型" dictCode="itsm_type" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <!-- <a-input v-model="model.status" placeholder="请输入状态"  ></a-input> -->
               <!-- 文档分类改为下拉框 从字典中获取 传给后台的是中文汉字 -->
               <j-dict-select-tag v-model="model.status" placeholder="请选择状态" dictCode="itsm_status" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input-number v-model="model.quantity" placeholder="请输入数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备管理人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentManager">
              <a-input v-model="model.equipmentManager" placeholder="请输入设备管理人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备固定资产编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentFixedAssetNo">
              <a-input v-model="model.equipmentFixedAssetNo" placeholder="请输入设备固定资产编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="IT资产编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="itAssetNumber">
              <a-input v-model="model.itAssetNumber" placeholder="请输入IT资产编号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="设备购买日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="equipmentPurchaseDate">
              <j-date placeholder="请选择设备购买日期" v-model="model.equipmentPurchaseDate"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remark">
              <a-textarea v-model="model.remark" rows="4" placeholder="请输入备注" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="录入日期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="entryDate">
              <j-date placeholder="请选择录入日期"  v-model="model.entryDate" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="录入人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enteredBy">
              <a-input v-model="model.enteredBy" placeholder="请输入录入人"  disabled></a-input>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'ChCurrentEquipmentManagementForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
          enteredBy:localStorage.getItem('userInfo')?JSON.parse(localStorage.getItem('userInfo')).realname:'',
          
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           name: [
              { required: true, message: '请输入名称!'},
           ],
           type: [
              { required: true, message: '请输入类型!'},
           ],
           status: [
              { required: true, message: '请输入状态!'},
           ],
           quantity: [
              { required: true, message: '请输入数量!'},
           ],
           equipmentManager: [
              { required: true, message: '请输入设备管理人!'},
           ],
           equipmentFixedAssetNo: [
              { required: true, message: '请输入设备固定资产编号!'},
           ],
           itAssetNumber: [
              { required: true, message: '请输入IT资产编号!'},
           ],
           equipmentPurchaseDate: [
              { required: true, message: '请输入设备购买日期!'},
           ],
           remark: [
              { required: true, message: '请输入备注!'},
           ],
           entryDate: [
              { required: true, message: '请输入录入日期!'},
           ],
           enteredBy: [
              { required: true, message: '请输入录入人!'},
           ],
        },
        url: {
          add: "/ch/chCurrentEquipmentManagement/add",
          edit: "/ch/chCurrentEquipmentManagement/edit",
          queryById: "/ch/chCurrentEquipmentManagement/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>